package day3

import scala.collection.mutable.ArrayBuffer

object Test3_Array_ArrayBuffer {
  def main(args: Array[String]): Unit = {
    var arr = new Array[String](3)
    arr(0) = "zs"
    arr(1) = "ls"
    arr(2) = "ww"

    // +: 向集合前边添加       :+ 向集合后边添加
    var arr3 = arr.:+ ("yy") // 向arr中添加元素，arr本身不会改变，会返回一个新的数组

    for (i <- arr3) {
      println(i)
    }

    println("--------------------")

    var arr2 = Array("sh","ls","sb","yy")
    for (a1 <- arr2) {
      println(a1)
    }


    println(arr.length)

    val arrayBuffer = new ArrayBuffer[String]()
    // 添加
    arrayBuffer.append("余生")
    arrayBuffer.append("美好")
    arrayBuffer.append("苦难")
    arrayBuffer.append("生活")
    // 删除
    arrayBuffer.remove(1)
    // 修改
    arrayBuffer.update(1,"疾苦")
    // 查询
    println("根据下标得" + arrayBuffer(0))
    for (j <- arrayBuffer) {
      println(j)
    }

    println(arrayBuffer)
    println(arrayBuffer + "哈哈哈")
  }
}
